//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Spreadsheet.Expressions;

namespace OpenLS.Spreadsheet
{
    static class ExpressionHelper
    {
        internal static IEnumerable<Expression> GetAllExpressions(Expression exp)
        {
            yield return nonSharedExpression(exp);
            foreach (Expression e in exp.GetSubExpressions())
            {
                foreach (Expression ee in GetAllExpressions(e))
                {
                    yield return nonSharedExpression(ee);
                }
            }
        }
        static Expression nonSharedExpression(Expression e)
        {
            if (e is SharedExpressionReference)
            {
                SharedExpressionReference se = (SharedExpressionReference)e;
                return se.ActualExpression;
            }
            return e;
        }
    }
}